package org.seedframework.sharding.resource;

import org.springframework.util.StringUtils;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Temporal hold data source pool
 */
public class ShardingDataSourcePoolContext {

    public static final String DEFAULT_DATA_SOURCE = "default-0";


    private static Map<String, ShardingDataSource> dataSourceMap = new HashMap<>();

    public static void addDataSource(String key, ShardingDataSource dataSource) {
        dataSourceMap.put(key, dataSource);
    }



    public static ShardingDataSource getDataSource(String key) {
        if (!StringUtils.hasText(key)) {
            dataSourceMap.get(DEFAULT_DATA_SOURCE);
        }
        return dataSourceMap.get(key);
    }

    public static Map<String, ShardingDataSource> getDataSourceWithKey(){
        return dataSourceMap;
    }

    public static Collection<ShardingDataSource> getShardingDataSource(){
        return dataSourceMap.values();
    }

}
